package com.sqsf.test;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

@Configuration
//使用注解读取properties配置文件并使用
@PropertySource("classpath:jdbc.properties")
public class DruidConfig {
    //使用@Value("${name}")将数据注入属性
    @Value("${jdbc.driver}")
    private String driver;
    @Value("${jdbc.url}")
    private String url;
    @Value("${jdbc.username}")
    private String username;
    @Value("${jdbc.password}")
    private String password;
    //因为我们无法修改工具类内容 所以无法添加注解
    //所以工具类进行配置需要我们书写方法返回对象
    @Bean("druid")//<bean id="druid"  factory-bean="springConfig" factory-method="druid"></bean>
    public DruidDataSource druid(){
        DruidDataSource druid=new DruidDataSource();
        druid.setDriverClassName(driver);
        druid.setUrl(url);
        druid.setUsername(username);
        druid.setPassword(password);
        return druid;
    }
}
